package com.hibernate.hrm.entity.dto.contract;

import com.hibernate.hrm.entity.Contract;
import com.hibernate.hrm.entity.User;
import lombok.Data;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

@Data
public class ContractExportDTO {
    private String contractNumber;
    private String contractName;
    private String contractType;
    private String partyAName;
    private String partyADepartment;
    private String partyBName;
    private String partyBDepartment;
    private String effectiveDate;
    private String expiryDate;
    private String status;
    private String workPosition;
    private String workLocation;
    private String entrustContent;
    private String entrustScope;
    private String serviceContent;
    private String penaltyRate;
    private String legalClauseAnalysis;

    public static ContractExportDTO fromContractDetail(ContractDetailDTO detail) {
        ContractExportDTO dto = new ContractExportDTO();
        dto.setContractNumber(detail.getContractNumber());
        dto.setContractName(detail.getContractName());
        dto.setContractType(detail.getContractType().name());
        dto.setPartyAName(detail.getSigningPartyA().getRealName());
        dto.setPartyADepartment(detail.getSigningPartyA().getDepartmentID().getDepartmentName());
        dto.setPartyBName(detail.getSigningPartyB().getRealName());
        dto.setPartyBDepartment(detail.getSigningPartyB().getDepartmentID().getDepartmentName());
        dto.setEffectiveDate(formatDate(detail.getEffectiveDate()));
        dto.setExpiryDate(formatDate(detail.getExpiryDate()));
        dto.setStatus(detail.getStatus().name());
        dto.setWorkPosition(detail.getWorkPosition());
        dto.setWorkLocation(detail.getWorkLocation());
        dto.setEntrustContent(detail.getEntrustContent());
        dto.setEntrustScope(detail.getEntrustScope());
        dto.setServiceContent(detail.getServiceContent());
        dto.setPenaltyRate(detail.getPenaltyRate() != null ? detail.getPenaltyRate().toString() : "无");
        dto.setLegalClauseAnalysis(detail.getLegalClauseAnalysis());
        return dto;
    }

    private static String formatDate(LocalDate date) {
        return date != null ? date.format(DateTimeFormatter.ofPattern("yyyy年MM月dd日")) : "";
    }
}
